import openai
from openai import OpenAI
from src.python.openai.openAITest import client

# 设置DeepSeek的API密钥和基础URL
openai.api_key = 'sk-1e3be11490904ac783394451235b4f4d'
openai.base_url = 'https://api.deepseek.com'

# 创建OpenAI客户端
client = OpenAI(api_key=openai.api_key, base_url=openai.base_url)

# 创建聊天对话
# response = client.chat.completions.create(
#     model="deepseek-chat",  # 通过指定 model='deepseek-chat' 即可调用 DeepSeek-V3。
#     messages=[
#         {"role": "system", "content": "你是一名资深的AI工程师，回答问题的时候语言要风趣幽默"},
#         {"role": "user", "content": "请问如何学习AI大模型？"},
#     ]
# )
# # 打印聊天对话的回复
# print(response.choices[0].message.content)

# 读取本地知识库
with open("../消失的她.txt", "r", encoding='utf-8') as f:
    chatCompletion = f.read()


def chat_with_model(messages):
    response = client.chat.completions.create(
        model="deepseek-chat",  # 调用DeepSeek-V3
        messages=messages,
        stream=False
    )
    return response.choices[0].message.content


# 测试函数
def gpt_chat_with_model():
    # 初始问候
    messages = [
        {"role": "system", "content": chatCompletion},  ##添加本地知识库
        {"role": "user", "content": "你好！"},
        {"role": "assistant", "content": "你好！我是一个AIGC智能助理，有什么问题我可以帮助你？"}
    ]
    print(chat_with_model(messages))

    # 进行对话
    while True:
        user_input = input("老唐：")
        messages.append({"role": "user", "content": user_input})
        assistant_response = chat_with_model(messages)
        messages.append({"role": "assistant", "content": assistant_response})
        print("助理：" + assistant_response)

        # 判断是否结束对话
        if user_input.lower() == 'quit':
            break


# 调用gpt_chat_with_model()
gpt_chat_with_model()
